#pragma once

#include <iostream>
#include <vector>
#include <string>
//#include <opencv2/opencv.hpp>

extern "C" {
	#include <libavcodec/avcodec.h>
	#include <libavutil/pixfmt.h>
	#include <libswscale/swscale.h>
	#include <libavutil/avutil.h>
}

#include "../common.h"
#include "base_decoder.h"

using namespace std;
using namespace cv;

class FFmpegDecoder : public BaseDecoder {
//class FFmpegDecoder {

public:
	FFmpegDecoder(CODEC_TYPE p_codec_id);
	virtual ~FFmpegDecoder();

	virtual int init();
	virtual int decodeFrame(Mat& frame, int& gotFrame, unsigned char* encode_buffer, int buffer_length, int& used_length);
	virtual void close();

private:
	CODEC_TYPE codec_id;

	AVPacket packet;
	AVCodec *pCodec;
	AVCodecContext *pCodecCtx;
	AVCodecParserContext *pCodecParserCtx;
	AVFrame *pFrame;
	AVFrame *pFrameYUV;
	struct SwsContext *img_convert_ctx;
	unsigned char* out_buffer;
	bool first_time;
	int y_size;
};
